<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>其他合同确权新增</title>
</head>
<style>
	.fieldset{
		margin-top: 5px;
		margin-bottom: 0px
	}
	.layui-legend{
		background-color:#5fb878;
		font-size:15px !important;
		width:140px;
	}
	.layui-form-item {
	    margin-bottom: 5px;
	    clear: both;
	    *zoom: 1;
	}
	.layui-form-label{width: 160px;}
</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
	    <div class="layui-tab-item layui-show">
	    	<div style="padding-top:15px;">&nbsp;</div>
			<form class="layui-form" id="addInfo_form" lay-filter="add_info_from">
				<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
				  <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">项目基础信息  ></legend>
				  <div style="margin-top:20px">
				  	<div class="layui-form-item">
				  		<div class="layui-inline">
					      	<label class="layui-form-label">申请公司</label>
					      	<div class="layui-input-inline">
								<input type="text" value="${bindOrgName}" style="border:0px;width:220px" readonly="readonly" class="layui-input">
					      	</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">申请部门</label>
				      		<div class="layui-input-inline">
								<input type="text" value="${bindDeptName}" style="border:0px;" readonly="readonly" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">申请人</label>
				      		<div class="layui-input-inline">
				        		<input type="text" value="${staffName }" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
				    </div>
				    <div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">合同类型</label>
							<div class="layui-input-inline">
								<input type="text" value="其他合同" style="border: 0px;" readonly="readonly" class="layui-input">
							</div>
						</div>
				    	<div class="layui-inline">
							<label class="layui-form-label">合同名称</label>
							<div class="layui-input-inline">
								<select name="otherCotId" id="select_otherCot" lay-verify="required" lay-filter="add_select_otherId" lay-search>
									<option value="">请选择</option>
									<c:if test="${not empty otherCots}">
										<c:forEach items="${otherCots}" var="otherCot">
											<option value="${otherCot.id}">${otherCot.proName}_${otherCot.otherCotName}</option>
										</c:forEach>
									</c:if>
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">合同单位名称</label>
							<div class="layui-input-inline">
								<input type="text" value="" id="query-input-sgCoopName" name="sgCoopName" style="border: 0px;width:220px" readonly="readonly" class="layui-input">
								<input type="hidden" name="sgCoopId" id="query-input-sgCoopId" class="layui-input">
							</div>
						</div>
					</div>
				    <div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">项目名称</label>
							<div class="layui-input-inline">
				        		<input type="text" id="proName" name="proName" readonly="readonly" style="border:0px;width:220px" class="layui-input">
						        <input type="hidden" id="types" name="types" value="1">
						        <input type="hidden" id="sgCityId" name="sgCityId">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">项目编号</label>
							<div class="layui-input-inline">
								<input type="text" value="" id="proCode" name="proCode" style="border: 0px;" readonly="readonly" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">区域公司</label>
							<div class="layui-input-inline">
								<input type="hidden" value="" id="query-input-hrOrgAreaId" name="hrOrgAreaId" readonly="readonly" class="layui-input">
								<input type="text" value="" id="query-input-hrOrgAreaName" name="orgAreName" style="border: 0px;width:220px" readonly="readonly" class="layui-input">
							</div>
						</div>
				    </div>
				    <div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">项目公司</label>
							<div class="layui-input-inline">
								<input type="hidden" id="query-input-hrOrgProId" name="hrOrgProId" readonly="readonly" class="layui-input">
								<input type="text" value="" id="query-input-hrOrgProName" name="orgProName" style="border: 0px;width:220px" readonly="readonly" class="layui-input">
							</div>
						</div>
			  			<div class="layui-inline">
							<label class="layui-form-label">实施机构</label>
							<div class="layui-input-inline">
								<input type="text" id="query-input-carryOrg" style="border: 0px;width:220px" name="carryOrg" readonly="readonly" class="layui-input">
							</div>
						</div>
				   		<div class="layui-inline">
							<label class="layui-form-label">项目地址</label>
							<div class="layui-input-inline">
								<input type="text" value="" id="query-input-proCityName" name="sgCityName" style="border: 0px;" readonly="readonly" class="layui-input">
							</div>
						</div>
				    </div>
				    <div class="layui-form-item">
				    	<div class="layui-inline">
							<label class="layui-form-label">项目负责人</label>
							<div class="layui-input-inline">
								<input type="text" value="" id="query-input-proLeader" style="border: 0px;" name="proLeader" readonly="readonly" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">确权月份</label>
							<div class="layui-input-inline">
								<input type="text" class="layui-input" id="sent-laydate-year" name="sureMonthStr" lay-verify="required" readonly>
							</div>
						</div>
					</div>
		  		</div>
			</fieldset>
				<fieldset class="layui-elem-field layui-field-title fieldset" id="houseInfo">
			  		<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">确权明细 ></legend>
				  	<div style="margin-top:20px">
				  		<div class="layui-form-item" style="margin: 0 20px;">
				  			<table class="layui-table layuiadmin-page-table" lay-skin="line">
				  				<thead>
				                    <tr>
				                      <th></th>
				                      <th></th>
				                      <th></th>
				                      <th></th>
				                      <th>合同金额（元）</th>
				                      <th>申报数量</th>
				                      <th>申报金额（元）</th>
				                      <th>对内确权数量</th>
				                      <th>当月对内确权金额（元）</th>
				                      <th>开累对内确权金额（元）</th>
				                    </tr> 
				                    <tr>
				                      <td width="50px;">合计</td>
				                      <td></td>
				                      <td></td>
				                      <td></td>
				                      <td><input type="text" id="sumTotal" name="totalSum" style="border:0px;" readonly="readonly" class="layui-input"></td>
				                      <td><input type="text" id="applyNumsTotal" name="applyNums" style="border: 0px;width:80px" readonly="readonly" class="layui-input"></td>
				                      <td><input type="text" id="applyAmountTotal" name="applyAmount" style="border: 0px;" readonly="readonly" class="layui-input"></td>
				                      <td><input type="text" id="sureNumsTotal" name="sureNums" style="border: 0px;width:90px" readonly="readonly" class="layui-input"></td>
				                      <td><input type="text" id="monthSureAmountTotal" name="monthSureAmount" style="border: 0px;" readonly="readonly" class="layui-input"></td>
				                      <td><input type="text" id="addupSureAmountTotal" name="addupSureAmount" style="border: 0px;" readonly="readonly" class="layui-input"></td>
				                    </tr> 
			                  	</thead>
			                  <thead>
			                    <tr>
			                      <th>序号</th>
			                      <th>分部分项清单名称</th>
			                      <th>计量单位</th>
			                      <th>合同单价（元）</th>
			                      <th>合同金额（元）</th>
			                      <th>申报数量</th>
			                      <th>申报金额（元）</th>
			                      <th>对内确权数量</th>
			                      <th>当月对内确权金额（元）</th>
			                      <th>开累对内确权金额（元）</th>
			                    </tr> 
			                  </thead>
			                  <tbody id="detail">
			                  </tbody>
			                </table>
					    </div>
				  	</div>
				</fieldset>
				<fieldset class="layui-elem-field layui-field-title fieldset" >
			  		<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">附件  ></legend>
					  	<div style="margin-top:20px;">
						    <div class="layui-form-item">
							    <label class="layui-form-label" style="width:350px;">支持pdf、excel、word、图片资料，可上传多个</label>
							</div>
						    <div class="layui-form-item">
							    <label class="layui-form-label">计算稿（选填）</label>
							    <div class="layui-input-block">
							    	<div class="layui-upload">
						              	<button type="button" class="layui-btn" id="11-upload-more">上传</button>
				                		<div class="layui-upload-list" id="11-upload-more-list">
				                		</div>
						            </div>
							    </div>
						  	</div>
						    <div class="layui-form-item">
							    <label class="layui-form-label">签字扫描件（选填）</label>
							    <div class="layui-input-block">
							    	<div class="layui-upload">
						              	<button type="button" class="layui-btn" id="12-upload-more">上传</button>
				                		<div class="layui-upload-list" id="12-upload-more-list">
				                		</div>
						            </div>
							    </div>
						  	</div>
						    <div class="layui-form-item">
							    <label class="layui-form-label">其他附件（选填）</label>
							    <div class="layui-input-block">
							    	<div class="layui-upload">
						              	<button type="button" class="layui-btn" id="4-upload-more">上传</button>
				                		<div class="layui-upload-list" id="4-upload-more-list">
				                		</div>
						            </div>
							    </div>
						  	</div>
					  	</div>
				</fieldset>
				<div class="layui-form-item" style="position: fixed ! important; right: 30px; bottom:45%;z-index:10000;">
					<div class="layui-input-block">
			      		<button class="layui-btn layui-bg-blue layui-btn-normal layui-btn-lg  layui-btn-radius" type="button" lay-submit lay-filter="addInfo_form_submit" id="addInfo_form_submit">
			      		<i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i>
			      		提交
			      		</button>
			      	</div>
			    </div>
			</form>
  		</div>
	</div>
</div>
  <script>
	//静态资源路径前缀
	var staticPath = '${fileHttpPre}';
	var stateJSON = <infopub:dicJson groupNo="A00010028" />;
	
  layui.config({
    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set', 'upload', 'element', 'laydate'], function(){
    var $ = layui.$
    ,form = layui.form
    ,element = layui.element
    ,laydate = layui.laydate
    ,upload = layui.upload;
    
    laydate.render({
	      elem: '#sent-laydate-year'
	      ,type: 'month'
		});
 	// 正则校验
	form.verify({
		//验证汉字
	    CHS:[
	    	/^[\u0391-\uFFE5]+$/
	    	,'只能输入汉字'
	  	],
	  	//大于0的正整数
	  	intNumber:[
			/^[1-9]\d*$/
			,'请输入正确的数字'
	  	],
	  	//数字只能有两位小数
	  	floatNumber:[
			/^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			,'请输入正确的数字'
	  	],
	  	//数字大于0，并只能有两位小数
	  	floatAmount:[
			/^([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			//var pattern=/^((\d+\.\d*[1-9]\d{1})|(\d*[1-9]\d*\.\d{2}))$/; 
			,'请输入正确的数字'
	  	]
	});
	//上传附件
  	upload.render({
	      elem: '#11-upload-more'
	      ,url: basePath + '/otherSure/uploadAtt/'
	      ,data: {
	    	  types:11
	    		}
	      ,multiple: true
	      ,accept: 'file'
	      ,acceptMime: 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf'
	   	  ,before: function(obj){ //obj参数包含的信息
	   		    layer.load(); //上传loading
	   		  }
	      ,done: function(res){
	    	  //如果上传失败
	          if(res.code > 0){
	        	  layer.closeAll('loading'); //关闭loading
	        	  return layer.msg(res.msg,{icon: 7});
	          }
	          //上传完毕
	   	  	  if(res.entity != null && res.entity.length > 0){
				for(var i in res.entity){
					var otherSureAtt = res.entity[i];
					var arr = otherSureAtt.split("|");
					var imgSrc = "";
					var suffix = arr[1].substring(arr[1].lastIndexOf(".")+1,arr[1].length);
					if(suffix == 'jpg' || suffix == 'png'){
						imgSrc = "${fileHttpPre}/"+arr[3];
					}else{
						imgSrc = "${ctx}/resources/images/"+suffix+".jpg";
					}
	        		$('#11-upload-more-list').append('<div class="layui-upload-img-div" id="upload_img_'+arr[2]+'"><img src="'+imgSrc+'" title="'+ arr[1] +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''+"${fileHttpPre}"+arr[3] +'\');">查看</a><a href="javascript:void(0)" onclick="del(\''+arr[2]+'\')";>删除</a></div><p>'+arr[1]+'</p><input type="hidden" value="'+otherSureAtt+'" id="fileAtt_'+arr[2]+'" name="fileAtt11" ></input></div> ');
				}
		  	  }
	      }
	      ,allDone: function(obj){ //当文件全部被提交后，才触发
	    	  layer.closeAll('loading'); //关闭loading
	      }
	      ,error: function(){
	    	  layer.closeAll('loading'); //关闭loading
	          //上传失败
	          layer.msg("上传失败，请稍后再试~",{icon: 7});
	        }
	    });
	//上传附件
  	upload.render({
	      elem: '#12-upload-more'
	      ,url: basePath + '/otherSure/uploadAtt/'
	      ,data: {
	    	  types:12
	    		}
	      ,multiple: true
	      ,accept: 'file'
	      ,acceptMime: 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf'
	   	  ,before: function(obj){ //obj参数包含的信息
	   		    layer.load(); //上传loading
	   		  }
	      ,done: function(res){
	    	  //如果上传失败
	          if(res.code > 0){
	        	  layer.closeAll('loading'); //关闭loading
	        	  return layer.msg(res.msg,{icon: 7});
	          }
	          //上传完毕
	   	  	  if(res.entity != null && res.entity.length > 0){
				for(var i in res.entity){
					var otherSureAtt = res.entity[i];
					var arr = otherSureAtt.split("|");
					var imgSrc = "";
					var suffix = arr[1].substring(arr[1].lastIndexOf(".")+1,arr[1].length);
					if(suffix == 'jpg' || suffix == 'png'){
						imgSrc = "${fileHttpPre}/"+arr[3];
					}else{
						imgSrc = "${ctx}/resources/images/"+suffix+".jpg";
					}
	        		$('#12-upload-more-list').append('<div class="layui-upload-img-div" id="upload_img_'+arr[2]+'"><img src="'+imgSrc+'" title="'+ arr[1] +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''+"${fileHttpPre}"+arr[3] +'\');">查看</a><a href="javascript:void(0)" onclick="del(\''+arr[2]+'\')";>删除</a></div><p>'+arr[1]+'</p><input type="hidden" value="'+otherSureAtt+'" id="fileAtt_'+arr[2]+'" name="fileAtt12" ></input></div> ');
				}
		  	  }
	      }
	      ,allDone: function(obj){ //当文件全部被提交后，才触发
	    	  layer.closeAll('loading'); //关闭loading
	      }
	      ,error: function(){
	    	  layer.closeAll('loading'); //关闭loading
	          //上传失败
	          layer.msg("上传失败，请稍后再试~",{icon: 7});
	        }
	    });
	//上传附件
  	upload.render({
	      elem: '#4-upload-more'
	      ,url: basePath + '/otherSure/uploadAtt/'
	      ,data: {
	    	  types:4
	    		}
	      ,multiple: true
	      ,accept: 'file'
	      ,acceptMime: 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf'
	   	  ,before: function(obj){ //obj参数包含的信息
	   		    layer.load(); //上传loading
	   		  }
	      ,done: function(res){
	    	  //如果上传失败
	          if(res.code > 0){
	        	  layer.closeAll('loading'); //关闭loading
	        	  return layer.msg(res.msg,{icon: 7});
	          }
	          //上传完毕
	   	  	  if(res.entity != null && res.entity.length > 0){
				for(var i in res.entity){
					var otherSureAtt = res.entity[i];
					var arr = otherSureAtt.split("|");
					var imgSrc = "";
					var suffix = arr[1].substring(arr[1].lastIndexOf(".")+1,arr[1].length);
					if(suffix == 'jpg' || suffix == 'png'){
						imgSrc = "${fileHttpPre}/"+arr[3];
					}else{
						imgSrc = "${ctx}/resources/images/"+suffix+".jpg";
					}
	        		$('#4-upload-more-list').append('<div class="layui-upload-img-div" id="upload_img_'+arr[2]+'"><img src="'+imgSrc+'" title="'+ arr[1] +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''+"${fileHttpPre}"+arr[3] +'\');">查看</a><a href="javascript:void(0)" onclick="del(\''+arr[2]+'\')";>删除</a></div><p>'+arr[1]+'</p><input type="hidden" value="'+otherSureAtt+'" id="fileAtt_'+arr[2]+'" name="fileAtt4" ></input></div> ');
				}
		  	  }
	      }
	      ,allDone: function(obj){ //当文件全部被提交后，才触发
	    	  layer.closeAll('loading'); //关闭loading
	      }
	      ,error: function(){
	    	  layer.closeAll('loading'); //关闭loading
	          //上传失败
	          layer.msg("上传失败，请稍后再试~",{icon: 7});
	        }
	    });
	
   	//监听提交
  	form.on('submit(addInfo_form_submit)', function(data){
  		$("#addInfo_form_submit").removeAttr("lay-submit").removeClass("layui-bg-blue").addClass("layui-btn-disabled");
  		layer.load();
       	//提交 Ajax 成功后，静态更新表格中的数据
       	$.ajax({
           	type : 'post',
			url : basePath + '/otherSure/save',
           	data: $('#addInfo_form').serialize(),
			success:function(result){
				if(result.success){
					layer.closeAll('loading'); //关闭loading
					layer.msg('提交单据成功~',{icon: 1});
					//两秒后关闭当前页面
					setTimeout(function(){
						/**
						 * 查找父菜单，并刷新
						 */
						var topDoc = $(window.top.document);
						var path = basePath + '/otherSure/list';
						// 获取页面名称
						var name = topDoc.find(".layui-nav-item [lay-href^='" + path + "']").text();
						if(name == '' || name == null){
							name = '其他合同确权';
						}
						window.parent.layui.index.openTabsPage(path, name);
						var iframe = window.parent.layui.admin.tabsBody(window.parent.layui.admin.tabsPage.index).find(".layadmin-iframe");
						iframe[0].contentWindow.location.reload(true);
						
						/**
						 * 关闭当前页
						 */
						var currPath = basePath + '/otherSure/add';
						var layid = topDoc.find("li[lay-id^='" + currPath + "']").attr('lay-id');
						window.parent.layui.element.tabDelete('layadmin-layout-tabs', layid);//关闭当前页
				        }, 2000);
				}else{
					layer.closeAll('loading'); //关闭loading
  					$("#addInfo_form_submit").removeClass("layui-btn-disabled").addClass("layui-bg-blue").attr("lay-submit","");
					layer.msg(result.msg,{icon: 7});
			  	}
			}
       	});
   	});  
 	// data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
 	
  	//新增-select监听
    form.on('select(add_select_otherId)', function(data){
    	var proId = data.value;
    	getOtherCotById(proId)
		$("#applyNumsTotal").val('');
		$("#applyAmountTotal").val('');
		$("#sureNumsTotal").val('');
		$("#monthSureAmountTotal").val('');
		$("#addupSureAmountTotal").val('');
	});
  	
  });
  
   function getOtherCotById(id){
	   var $ = layui.$
	  	,form = layui.form;
		$.ajax({
			type : "POST", //提交方式  
			url : "${ctx}/otherSure/getOtherCotById",//路径  
			data : {
				"id" :id
			},//数据，这里使用的是Json格式进行传输  
			success : function(result) {//返回数据根据结果进行相应的处理 
				if(result.flag==true){
					form.val('add_info_from',result.otherCotVo); // 填充原值
					var otherCotLists = result.otherCotVo.otherCotLists;
					$("#detail").html('');
					var tableTemplate = [];
					layui.$.each(otherCotLists ,function (index, price){
						var ind = index + 1;
						var thisid = index;
						tableTemplate.push('<tr id="linkRow'+ind+'">');
						tableTemplate.push('<td><input type="text" name="otherSureDetails['+thisid+'].showIdx" value="'+price.showIdx+'" style="border: 0px;width:50px" readonly="readonly" class="layui-input"></td>');
						tableTemplate.push('<td><input type="text" name="otherSureDetails['+thisid+'].subName" value="'+price.subName+'" style="border: 0px;" readonly="readonly" class="layui-input"></td>');
						tableTemplate.push('<td><input type="text" name="otherSureDetails['+thisid+'].subUnit" value="'+price.subUnit+'" style="border: 0px;" readonly="readonly" class="layui-input"></td>');
						tableTemplate.push('<td><input type="text" name="otherSureDetails['+thisid+'].cotUnitPrice" value="'+price.cotUnitPrice+'" style="border: 0px;width:100px" readonly="readonly" class="layui-input"></td>');
						tableTemplate.push('<td><input type="text" name="otherSureDetails['+thisid+'].cotSumPrice" value="'+price.cotSumPrice+'" style="border: 0px;" readonly="readonly" class="layui-input"><input type="hidden" name="otherSureDetails['+thisid+'].cotNums" value="'+price.cotNums+'"></td>');
						tableTemplate.push('<td><input type="text" name="otherSureDetails['+thisid+'].applyNums" maxlength="10" onblur="calcSumAmount(this);" style="width:80px" lay-verify="required|floatNumber"  autocomplete="off" class="layui-input"></td>');
						tableTemplate.push('<td><input type="text" name="otherSureDetails['+thisid+'].applyAmount" maxlength="15" style="border: 0px;" readonly="readonly" class="layui-input"></td>');
						tableTemplate.push('<td><input type="text" name="otherSureDetails['+thisid+'].sureNums" maxlength="10" onblur="calcSumAmount(this);" style="width:90px" lay-verify="required|floatNumber"  autocomplete="off" class="layui-input"></td>');
						tableTemplate.push('<td><input type="text" name="otherSureDetails['+thisid+'].monthSureAmount" style="border: 0px;" readonly="readonly" maxlength="15" lay-verify="required|floatNumber" class="layui-input"></td>');
						tableTemplate.push('<td><input type="text" name="otherSureDetails['+thisid+'].addupSureAmount" style="border: 0px;" readonly="readonly" class="layui-input"></td>');
						tableTemplate.push('</tr>');
                       // $table.append(html.join(''));                         
                    });
					var $div = $("#detail");
                    $div.append(tableTemplate.join(''));
					form.render();
				}else{
					layer.msg('未查到合同信息~',{icon: 0});
				}
			} 
		});
   }
   
	//计算合同总价
	function calcSumAmount(obj){
		var $ = layui.$;
		if (obj.value == '' || obj.value == null) {
			return;
		}
		var rgx = /^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;
		var boolrgx = rgx.test(obj.value);// true
		if(!boolrgx){
			obj.value=0;
			layer.msg('请输入正确数字，且保留两位小数！');
		}
		var name = $(obj).attr("name");
		var sumPrice = 0;
		//合同单价
		var price = $("input[name='"+name.split('.')[0]+".cotUnitPrice']").val();
		if(name.split('.')[1] == 'applyNums'){//申报数量
			sumPrice = parseFloat(obj.value)*parseFloat(price);
			$("input[name='"+name.split('.')[0]+".applyAmount']").val(sumPrice.toFixed(2));
			
			calcSum('applyNums');
			calcSum('applyAmount');
		}else if(name.split('.')[1] == 'sureNums'){//对内确权数量
			sumPrice = parseFloat(obj.value)*parseFloat(price);
			$("input[name='"+name.split('.')[0]+".monthSureAmount']").val(sumPrice.toFixed(2));
			
			//合同id
			var otherCotId = $("#select_otherCot").val();
			//分部分项名称
			var subName = $("input[name='"+name.split('.')[0]+".subName']").val();
			//获取历史确权金额
			var addupAmountTotal = getAddupAmount(subName,otherCotId);
			
			var addupSureAmount = parseFloat(addupAmountTotal) + sumPrice;
			$("input[name='"+name.split('.')[0]+".addupSureAmount']").val(addupSureAmount.toFixed(2));
			
			calcSum('sureNums');
			calcSum('monthSureAmount');
			calcSum('addupSureAmount');
		}else if(name.split('.')[1] == 'monthSureAmount'){//当月对内确权金额
			calcSum('monthSureAmount');
			//合同id
			var otherCotId = $("#select_otherCot").val();
			//分部分项名称
			var subName = $("input[name='"+name.split('.')[0]+".subName']").val();
			//获取历史确权金额
			var addupAmountTotal = getAddupAmount(subName,otherCotId);
			$("input[name='"+name.split('.')[0]+".addupSureAmount']").val(parseFloat(obj.value)+parseFloat(addupAmountTotal));
			calcSum('addupSureAmount');
		}
	}
	
	//获取历史确权金额
   	function getAddupAmount(subName,otherCotId){
	   var $ = layui.$
	  	,form = layui.form;
	   var addupAmountTotal = 0;
		$.ajax({
			type : "POST", //提交方式 
			async: false,
			url : "${ctx}/otherSure/getAddupAmountBySubNameAndRefId",//路径  
			data : {
				"subName" :subName,
				"refId" :otherCotId
			},//数据，这里使用的是Json格式进行传输  
			success : function(result) {//返回数据根据结果进行相应的处理 
				if(result.flag==true){
					addupAmountTotal = result.addupAmountTotal;
				}else{
					layer.msg('未查到该项的历史确权金额~',{icon: 0});
				}
			} 
		});
		return addupAmountTotal;
   	}
	
	//计算合计
	function calcSum(btnName){
		var $ = layui.$;
		var totalAmount = 0;
  		$("input[name$='."+btnName+"']").each(function(){
			var tId = $(this).val();
			if(tId != '' && parseFloat(tId) > 0){
				totalAmount = totalAmount + parseFloat(tId);
			}
		});
  		$("#"+btnName+"Total").val(totalAmount.toFixed(2));
	}
	//删除文件
	function del(index){
		layui.$("#fileAtt_"+index).remove();
		layui.$("#upload_img_"+index).remove();
	}
  
	//根据url查看文件
	function showImg(url){
		var openWin = window.open(url,'','left=410,height=768, width=1024, top=200,  toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
	}
  </script>
</body>
</html>

